package com.rc.evcharger.service.order;

import com.rc.evcharger.mapper.order.OrderDiscountRecordMapper;
import com.rc.evcharger.model.order.OrderDiscountRecord;
import com.rc.evcharger.model.order.OrderDiscountRecordExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * Create by Yang on 2019/11/28
 */
@Service
public class OrderDiscountRecordServiceImpl implements OrderDiscountRecordService {
    @Autowired
    private OrderDiscountRecordMapper orderDiscountRecordMapper;

    @Override
    public OrderDiscountRecordMapper getMapper() {
        return orderDiscountRecordMapper;
    }

    @Override
    public OrderDiscountRecord selectByOrderId(Long orderId) {
        OrderDiscountRecordExample example = new OrderDiscountRecordExample();
        example.createCriteria().andOrderIdEqualTo(orderId);

        List<OrderDiscountRecord> orderDiscountRecords = orderDiscountRecordMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(orderDiscountRecords)) {
            return null;
        }
        return orderDiscountRecords.get(0);
    }
}
